<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * Description of auth_model
 * 
 * @author Subha Sundar Das (subhasundar.das@gmail.com)
 */
class Auth_model extends CI_Model {

    //put your code here

    function __construct() {
        parent::__construct();
        log_message('debug', 'Model Initialized');
    }

    function member_login($email, $password) {
        $this->db->select('*');
        $this->db->where('email', $email);
        $this->db->where('password', $password);
        $this->db->where('status !=', '98');
        $query = $this->db->get("member_master");
        $result = $query->row();

        if ($query->num_rows() == 1) {
            $this->session->set_userdata('sess_member_id', $result->id);
            $this->session->set_userdata('sess_member_name', $result->name);
            $this->session->set_userdata('sess_member_email', $result->email);
            $this->session->set_userdata('sess_member_phone', $result->phone);
            $this->session->set_userdata('sess_member_password', $result->password);
            $this->session->set_userdata('sess_member_created_on', $result->created_on);
            $this->session->set_userdata('sess_member_last_login_date', $result->last_login_date);
            $this->session->set_userdata('sess_member_last_login_ip', $result->last_login_ip);

            //--update 
            $data = array
                (
                'last_login_date' => unix_to_human(time(), TRUE),
                'last_login_ip' => $this->input->ip_address(),
                'status' => 51
            );
            //--Update last_login n IP
            $this->db->where('email ', $email);
            $this->db->update('member_master', $data);

            return TRUE;
        } else {
            return FALSE;
        }
    }

}

?>
